package com.vietnam.power.util;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class SessionCounter implements HttpSessionListener {

	private static int totalActiveSessions;

	public static int getTotalActiveSession() {
		return totalActiveSessions;
	}

	public void sessionCreated(HttpSessionEvent arg0) {
		totalActiveSessions++;
		HttpSession session = arg0.getSession();
		session.setAttribute("counter", totalActiveSessions);
	}

	public void sessionDestroyed(HttpSessionEvent arg0) {
		totalActiveSessions--;
		HttpSession session = arg0.getSession();
		session.setAttribute("counter", totalActiveSessions);
	}

}
